package logic

import (
	"context"
	"local-life/models/mysql"

	"local-life/liferpc/internal/svc"
	"local-life/liferpc/liferpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShopAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopAddLogic {
	return &ShopAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopAddLogic) ShopAdd(in *liferpc.ShopAddRequest) (*liferpc.ShopAddResponse, error) {
	// todo: add your logic here and delete this line

	shop := mysql.Shop{
		ShopName: in.ShopName,
		Address:  in.Address,
		Phone:    in.Phone,
		State:    in.State,
		Price:    float64(in.Price),
		Image:    in.Image,
	}
	mysql.DB.Debug().Create(&shop)

	return &liferpc.ShopAddResponse{
		ShopId: int64(shop.ID),
	}, nil
}
